scoreboard players set @s faqv.villager_ball.use_ball 0
execute at @s positioned ^ ^ ^ anchored eyes run function faqv:villager_ball/try_create_villager
execute unless entity @n[type=villager, tag=faqv.villager_ball.villager_to_summon] run return 1

data modify entity @n[type=villager, tag=faqv.villager_ball.villager_to_summon] Brain set from entity @s SelectedItem.components."minecraft:custom_data".villager.Brain
data modify entity @n[type=villager, tag=faqv.villager_ball.villager_to_summon] CustomName set from entity @s SelectedItem.components."minecraft:custom_data".villager.CustomName
data modify entity @n[type=villager, tag=faqv.villager_ball.villager_to_summon] CustomNameVisible set from entity @s SelectedItem.components."minecraft:custom_data".villager.CustomNameVisible
data modify entity @n[type=villager, tag=faqv.villager_ball.villager_to_summon] Invulnerable set from entity @s SelectedItem.components."minecraft:custom_data".villager.Invulnerable
data modify entity @n[type=villager, tag=faqv.villager_ball.villager_to_summon] NoGravity set from entity @s SelectedItem.components."minecraft:custom_data".villager.NoGravity 
data modify entity @n[type=villager, tag=faqv.villager_ball.villager_to_summon] OnGround set from entity @s SelectedItem.components."minecraft:custom_data".villager.OnGround
data modify entity @n[type=villager, tag=faqv.villager_ball.villager_to_summon] Silent set from entity @s SelectedItem.components."minecraft:custom_data".villager.Silent
# data modify entity @n[type=villager, tag=faqv.villager_ball.villager_to_summon] Health set from entity @s SelectedItem.components."minecraft:custom_data".villager.Health
data modify entity @n[type=villager, tag=faqv.villager_ball.villager_to_summon] NoAI set from entity @s SelectedItem.components."minecraft:custom_data".villager.NoAI
data modify entity @n[type=villager, tag=faqv.villager_ball.villager_to_summon] AssignProfessionWhenSpawned set from entity @s SelectedItem.components."minecraft:custom_data".villager.AssignProfessionWhenSpawned
data modify entity @n[type=villager, tag=faqv.villager_ball.villager_to_summon] FoodLevel set from entity @s SelectedItem.components."minecraft:custom_data".villager.FoodLevel
data modify entity @n[type=villager, tag=faqv.villager_ball.villager_to_summon] Inventory set from entity @s SelectedItem.components."minecraft:custom_data".villager.Inventory 
data modify entity @n[type=villager, tag=faqv.villager_ball.villager_to_summon] Gossips set from entity @s SelectedItem.components."minecraft:custom_data".villager.Gossips
data modify entity @n[type=villager, tag=faqv.villager_ball.villager_to_summon] LastGossipDecay set from entity @s SelectedItem.components."minecraft:custom_data".villager.LastGossipDecay
data modify entity @n[type=villager, tag=faqv.villager_ball.villager_to_summon] LastRestock set from entity @s SelectedItem.components."minecraft:custom_data".villager.LastRestock
data modify entity @n[type=villager, tag=faqv.villager_ball.villager_to_summon] Offers set from entity @s SelectedItem.components."minecraft:custom_data".villager.Offers
data modify entity @n[type=villager, tag=faqv.villager_ball.villager_to_summon] RestocksToday set from entity @s SelectedItem.components."minecraft:custom_data".villager.RestocksToday
data modify entity @n[type=villager, tag=faqv.villager_ball.villager_to_summon] VillagerData set from entity @s SelectedItem.components."minecraft:custom_data".villager.VillagerData
data modify entity @n[type=villager, tag=faqv.villager_ball.villager_to_summon] Xp set from entity @s SelectedItem.components."minecraft:custom_data".villager.Xp

item modify entity @s weapon.mainhand faqv:set_ball_empty
tag @e[tag=faqv.villager_ball.villager_to_summon] remove faqv.villager_ball.villager_to_summon